#ifndef CCOPENGLWIDGET_H
#define CCOPENGLWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>

class QPropertyAnimation;
class CCOpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions
{
    Q_OBJECT
    Q_PROPERTY(qreal secondAngle READ secondAngle WRITE setSecondAngle)
public:
    explicit CCOpenGLWidget(QWidget *parent = nullptr);
    virtual ~CCOpenGLWidget();

    qreal secondAngle() const;
    void setSecondAngle(qreal value);

protected:
    virtual void initializeGL();
    virtual void resizeGL(int w, int h);
    virtual void paintGL();

private slots:
    void slotUpdateDateTime();

private:
    void drawDial(QPainter &painter);           // 表盘

    void drawYear(QPainter &painter);           // 年
    void drawMonth(QPainter &painter);          // 月
    void drawDay(QPainter &painter);            // 日
    void drawWeek(QPainter &painter);           // 星期
    void drawTime(QPainter &painter);           // 时辰
    void drawHour(QPainter &painter);           // 小时
    void drawMinute(QPainter &painter);         // 分钟
    void drawSecond(QPainter &painter);         // 秒

private:
    // 秒钟动画
    QPropertyAnimation *secondAnimation;

    // 角度
    qreal m_monthAngle;
    qreal m_dayAngle;
    qreal m_weekAngle;
    qreal m_timeAngle;
    qreal m_hourAngle;
    qreal m_minuteAngle;
    qreal m_secondAngle;

    // 临时值
    int m_daysInMonth;
    int m_year;
};

#endif // CCOPENGLWIDGET_H
